End-To-End Example: Plotting and Mapping Potholes

Let's do a data analysis of Syracuse Potholes based on data from the civic hackathon https://cityofsyracuse.github.io/RoadsChallenge/ 

We will plot data and display pothole locations on a map!


In [1]:
import folium
import pandas as pd

First we need to find the latitude and longitude of Syracuse, then estimate the appropriate zoom level...


In [2]:
SYR = (43.0481, -76.1474)
map = folium.Map(location=SYR, zoom_start=14)
map


Out[2]:

We get the data from the RoadsChallange github account


In [3]:
data = pd.read_csv('https://cityofsyracuse.github.io/RoadsChallenge/data/potholes.csv')
data.sample(5)


Out[3]:
StreetNumber StreetName StreetNamePostType Directional strLocation dtTime STREET_ID VehicleName Latitude Longitude
3924 500 ATLANTIC AVE 500 ATLANTIC AVE 5/20/2016 13:32 12571951 DP1 -76.154959 43.011060
5793 218 KENSINGTON PL 218-20 KENSINGTON PL 6/23/2016 10:06 12577545 DP2 -76.119679 43.029458
800 429 GRANT AVE 429-31 GRANT AVE & DUANE ST 4/19/2016 10:12 12572929 DP1 -76.178374 43.031453
1041 104 BRADLEY ST 104 BRADLEY ST 4/20/2016 13:22 12573075 DP1 -76.172207 43.036122
4029 314 ATLANTIC AVE 314 ATLANTIC AVE 5/21/2016 11:18 12571953 DP1 -76.153098 43.010862

Now we take the latitude and longitude of each pothole and show them on a map using circle markers


In [5]:
# NOTE: to_dict('records') converts a pandas dataframe back to a list of dict!
SYR = (43.0481, -76.1474)
map = folium.Map(location=SYR, zoom_start=14)
subset = data.sample(500)
for row in subset.to_records():
    coords = (row['Longitude'],row['Latitude'])
    loc = str(row['strLocation']) + ' ' + str(row['dtTime'])
    marker = folium.Circle(location=coords, radius=15, popup=loc,color='#3186cc',fill_color='#3186cc')
    map.add_child(marker)
    
map


Out[5]:

In [ ]: